package com.example.juc.lock;

import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.AtomicStampedReference;

public class SplnLockDemo {

    AtomicReference<Thread> reference = new AtomicReference<>();


    public void myLock(){
        Thread thread = Thread.currentThread();
        System.out.println(thread.getName()+"lock!");
        while (!reference.compareAndSet(null,thread)){

        }
    }

    public void myUnlock(){
        Thread thread = Thread.currentThread();
        System.out.println(thread.getName()+"unlock!");
        reference.compareAndSet(thread,null);
    }
}
